package com.shop.cereshop.commons.tencent.im.enums.redpacket;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @description: 红包状态枚举
 * @author zdd
 * @date 2025/9/3 11:27
 * @version 1.0
 */
public enum RedPacketStatusEnum {

    // 红包状态：0-创建未发送 1-未领取 2-未领完 3-已领完 4-已过期 5-已退款
    CREATE(0, "创建未发送"),
    NOT_RECEIVED(1, "未领取"),
    NOT_FINISHED(2, "未领完"),
    COMPLETED(3, "已领完"),
    EXPIRED(4, "已过期"),
    REFUNDED(5, "已退款");

    private final Integer code;
    private final String msg;

    private static final Map<Integer, RedPacketStatusEnum> CODE_MAP = new HashMap<>();

    static {
        for (RedPacketStatusEnum status : RedPacketStatusEnum.values()) {
            CODE_MAP.put(status.getCode(), status);
        }
    }

    RedPacketStatusEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public static String getMsgByCode(Integer code) {
        if (Objects.isNull(code)) {
            return "";
        }
        RedPacketStatusEnum status = CODE_MAP.get(code);
        return status != null ? status.getMsg() : "";
    }
}
